#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=210,INF=0x7fffffff;
LL n,d[MAXN],f[MAXN],cnt,cnt1,cnt2,Left[MAXN],Right[MAXN],last[MAXN],ans,head[MAXN],pri[32000],top;
bool vis[MAXN],ispri[32000];
struct edge
{
	LL v,next,cost,vol;
}e[MAXN*MAXN*2];
struct num
{
	LL a,b,c,f;
}a[MAXN];
queue<LL>q;
void addedge(LL u,LL v,LL a,LL b)
{
	e[cnt]=(edge){v,head[u],b,a};
	head[u]=cnt++;
	return;
}
void cal_prime_num(int n)
{
	for(int i=2;i<=n;++i)
	{
		if(!ispri[i])pri[++top]=i;
		for(int j=1;j<=top&&i*pri[j]<=n;++j)
		{
			ispri[i*pri[j]]=true;
			if(!i%pri[j])break;
		}
	}
}
void SPFA()
{
	memset(d,-127,sizeof(d));
	memset(vis,0,sizeof(vis));
	memset(last,-1,sizeof(last));
	memset(f,127,sizeof(f));
	while(!q.empty())q.pop();
	q.push(0);
	vis[0]=true;
	d[0]=0;
	while(!q.empty())
	{
		LL u=q.front();
		q.pop();
		vis[u]=false;
		for(LL i=head[u];~i;i=e[i].next)
		{
			LL v=e[i].v;
			if(!e[i].vol)continue;
			if(d[u]+e[i].cost>d[v])
			{
				d[v]=d[u]+e[i].cost;
				f[v]=min(f[u],e[i].vol);
				last[v]=i;
				if(!vis[v])
				{
					q.push(v);
					vis[v]=true;
				}
			}
		}
	}
	return;
}
LL cal_f(LL x)
{
	LL ans=0;
	for(LL i=1;i<=top;++i)
	{
		if(x==1)break;
		while(x%pri[i]==0)
		{
			x/=pri[i];
			++ans;
		}
	}
	return ans;
}
int main()
{
	memset(head,-1,sizeof(head));
	cal_prime_num(32000);
	scanf("%lld",&n);
	for(LL i=1;i<=n;++i)
	{
		scanf("%lld",&a[i].a);
		if(a[i].a>1)a[i].f=cal_f(a[i].a);
		else if(a[i].a<-1)a[i].f=cal_f(-a[i].a);
		if(a[i].f%2==0)Left[++cnt1]=i;
		else Right[++cnt2]=i;
	}
	for(LL i=1;i<=n;++i)scanf("%lld",&a[i].b);
	for(LL i=1;i<=n;++i)scanf("%lld",&a[i].c);
	for(LL i=1;i<=cnt1;++i)
	{
		for(LL j=1;j<=cnt2;++j)
		{
			if(a[Left[i]].f==a[Right[j]].f+1&&a[Left[i]].a%a[Right[j]].a==0||a[Left[i]].f==a[Right[j]].f-1&&a[Right[j]].a%a[Left[i]].a==0)
			{
				addedge(Left[i],Right[j],INF,a[Left[i]].c*a[Right[j]].c);
				addedge(Right[j],Left[i],0,-a[Left[i]].c*a[Right[j]].c);
			}
		}
	}
	for(LL i=1;i<=cnt1;++i)
	{
		addedge(0,Left[i],a[Left[i]].b,0);
		addedge(Left[i],0,0,0);
	}
	for(LL i=1;i<=cnt2;++i)
	{
		addedge(Right[i],n+1,a[Right[i]].b,0);
		addedge(n+1,Right[i],0,0);
	}
	LL now=0;
	while(true)
	{
		SPFA();
		if(last[n+1]==-1)break;
		if(now+d[n+1]*f[n+1]<0)
		{
			ans-=(now/d[n+1]);
			break;
		}
		ans+=f[n+1];
		now+=d[n+1]*f[n+1];
		LL x=n+1;
		while(~last[x])
		{
			e[last[x]].vol-=f[n+1];
			e[last[x]^1].vol+=f[n+1];
			x=e[last[x]^1].v;
		}
	}
	printf("%lld\n",ans);
	return 0;
}
